using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_PROCESS_TRAININGData : DatabaseObjectBase
	{
		public HRM_PROCESS_TRAININGData()
		{
			Initialize(true);
		}
		public HRM_PROCESS_TRAININGData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_PROCESS_TRAINING_Insert(Guid TrainingID, String EmployeeCode, String TrainingName, String Reason, String Form, String Time, DateTime BeginDate, DateTime Date, String DecideNumber, String Person, String FilePath)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_PROCESS_TRAINING_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@TrainingID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@TrainingName", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Form", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Time", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@BeginDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@FilePath", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Prepare();
				SqlGuid TrainingIDSQL = TrainingID;
				_dbadapter.InsertCommand.Parameters["@TrainingID"].Value = TrainingIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.InsertCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString TrainingNameSQL = TrainingName;
				_dbadapter.InsertCommand.Parameters["@TrainingName"].Value = TrainingNameSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.InsertCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString FormSQL = Form;
				_dbadapter.InsertCommand.Parameters["@Form"].Value = FormSQL;
				SqlString TimeSQL = Time;
				_dbadapter.InsertCommand.Parameters["@Time"].Value = TimeSQL;
				SqlDateTime BeginDateSQL = SqlDateTime.Null;
				if (BeginDate > DateTime.MinValue)
				{
					try
					{
						BeginDateSQL = BeginDate;
					}
					catch (Exception eBeginDate)
					{
						String BeginDateMessage = eBeginDate.Message;
						BeginDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@BeginDate"].Value = BeginDateSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Date"].Value = DateSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.InsertCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString PersonSQL = Person;
				_dbadapter.InsertCommand.Parameters["@Person"].Value = PersonSQL;
				SqlString FilePathSQL = FilePath;
				_dbadapter.InsertCommand.Parameters["@FilePath"].Value = FilePathSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_TRAINING_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_TRAINING_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_TRAINING_Update(Guid TrainingID, String EmployeeCode, String TrainingName, String Reason, String Form, String Time, DateTime BeginDate, DateTime Date, String DecideNumber, String Person, String FilePath)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_TRAINING_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@TrainingID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@TrainingName", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Form", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Time", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@BeginDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FilePath", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid TrainingIDSQL = TrainingID;
				_dbadapter.UpdateCommand.Parameters["@TrainingID"].Value = TrainingIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString TrainingNameSQL = TrainingName;
				_dbadapter.UpdateCommand.Parameters["@TrainingName"].Value = TrainingNameSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString FormSQL = Form;
				_dbadapter.UpdateCommand.Parameters["@Form"].Value = FormSQL;
				SqlString TimeSQL = Time;
				_dbadapter.UpdateCommand.Parameters["@Time"].Value = TimeSQL;
				SqlDateTime BeginDateSQL = SqlDateTime.Null;
				if (BeginDate > DateTime.MinValue)
				{
					try
					{
						BeginDateSQL = BeginDate;
					}
					catch (Exception eBeginDate)
					{
						String BeginDateMessage = eBeginDate.Message;
						BeginDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@BeginDate"].Value = BeginDateSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString PersonSQL = Person;
				_dbadapter.UpdateCommand.Parameters["@Person"].Value = PersonSQL;
				SqlString FilePathSQL = FilePath;
				_dbadapter.UpdateCommand.Parameters["@FilePath"].Value = FilePathSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_TRAINING_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_TRAINING_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_TRAINING_Disable(Guid TrainingID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_TRAINING_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@TrainingID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid TrainingIDSQL = TrainingID;
				_dbadapter.UpdateCommand.Parameters["@TrainingID"].Value = TrainingIDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_TRAINING_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_TRAINING_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_TRAINING_Delete(Guid TrainingID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_PROCESS_TRAINING_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@TrainingID", SqlDbType.UniqueIdentifier));
				_dbadapter.DeleteCommand.Prepare();
				SqlGuid TrainingIDSQL = TrainingID;
				_dbadapter.DeleteCommand.Parameters["@TrainingID"].Value = TrainingIDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_TRAINING_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_TRAINING_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_TRAINING_Save(Guid TrainingID, String EmployeeCode, String TrainingName, String Reason, String Form, String Time, DateTime BeginDate, DateTime Date, String DecideNumber, String Person, String FilePath)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_TRAINING_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@TrainingID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@TrainingName", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Form", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Time", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@BeginDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FilePath", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid TrainingIDSQL = TrainingID;
				_dbadapter.UpdateCommand.Parameters["@TrainingID"].Value = TrainingIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString TrainingNameSQL = TrainingName;
				_dbadapter.UpdateCommand.Parameters["@TrainingName"].Value = TrainingNameSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString FormSQL = Form;
				_dbadapter.UpdateCommand.Parameters["@Form"].Value = FormSQL;
				SqlString TimeSQL = Time;
				_dbadapter.UpdateCommand.Parameters["@Time"].Value = TimeSQL;
				SqlDateTime BeginDateSQL = SqlDateTime.Null;
				if (BeginDate > DateTime.MinValue)
				{
					try
					{
						BeginDateSQL = BeginDate;
					}
					catch (Exception eBeginDate)
					{
						String BeginDateMessage = eBeginDate.Message;
						BeginDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@BeginDate"].Value = BeginDateSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString PersonSQL = Person;
				_dbadapter.UpdateCommand.Parameters["@Person"].Value = PersonSQL;
				SqlString FilePathSQL = FilePath;
				_dbadapter.UpdateCommand.Parameters["@FilePath"].Value = FilePathSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_TRAINING_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_TRAINING_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_TRAINING_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_TRAINING_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_TRAINING_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_TRAINING_Get(Guid TrainingID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_TRAINING_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@TrainingID", SqlDbType.UniqueIdentifier));
				_dbadapter.SelectCommand.Prepare();
				SqlGuid TrainingIDSQL = TrainingID;
				_dbadapter.SelectCommand.Parameters["@TrainingID"].Value = TrainingIDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_TRAINING_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
